let ImportService = require('./ImportService')
let Mongodb = require('../../database/mongodb');

class TestCaseService extends ImportService{
  initParam () {
    this.tableConfigs = [
      { tableName: 'users' }
    ]
    this.enumTypes = ['EQ_TYPE', 'OPP_COMPANY', 'CONTACT', 'EQ_USE', 'EQ_MODEL']
  }

  formateData (dataList) {
    return new Promise((resolve, reject) => {
      let rowDatas = []
      let data = {}
      // 1.数据转换
      for (let i = 1, len = dataList.length; i < len; i++) {
        data = dataList[i]
        rowDatas.push({
          "eqType": this.dataFormater('EQ_TYPE', data[1], 'value', 'name'),
          "eqModel": this.dataFormater('EQ_MODEL', data[2], 'value', 'name'),
          "count": data[3],
          "use": this.dataFormater('EQ_USE', data[4], 'value', 'name'),
          "sendDate": new Date(data[5]),
          "sendInfo": data[6],
          "toUser": data[7],
          "toUserPhone": data[8],
          "saleUser": this.dataFormater('users', data[9], 'email', 'userName'),
          "customerCompany": data[10],
          "ygCompany": this.dataFormater('OPP_COMPANY', data[11], 'value', 'name'),
          "TNO": data[12],
          "sendCompany": this.dataFormater('CONTACT', data[13], 'value', 'name'),
          "serialNumber": data[14],
          "note": data[15],
          "finalcost": Number(data[16]),
          "PC": data[17],
          "payinfo": data[18],
          "orderno": data[19],
          "orgId": this.user.orgId[0],
          "createDate": new Date(),
          "createUser": this.user.email,
        })        
      }
      resolve(rowDatas)
    })
  }
}

module.exports = new TestCaseService()